package com.wondersgroup.wuhan_demo.net;



import android.util.Log;

import com.wondersgroup.wuhan_demo.Constant;

import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

/**
 * Created by yangjinxi on 2016/4/26.
 */
public class OkHttpHelper {
    private static Map<String, String> headers = null;

    public static Map<String, String> getHeaders() {
        if (headers == null) {
            headers = new HashMap<>();
            headers.put("Content-Type", "text/xml;charset=UTF-8");
            headers.put("SOAPAction", "");
            headers.put("Connection", "Keep-Alive");
            headers.put("User-Agent", "OkHttp Headers.java");
        }
        return headers;
    }
    public static String requestContent(Vector<Param> v, String method){
        String namespace = Constant.NAMESPACE;
        if (v == null || method == null || namespace == null){
            return "";
        }
        StringBuffer sb = new StringBuffer("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:card=\"");
        sb.append(namespace);
        sb.append("\">");
        sb.append("<soapenv:Header/>");
        sb.append("<soapenv:Body>");
        sb.append("<card:");
        sb.append(method);
        sb.append(">");
        for (int i = 0; i < v.size(); i++) {
            Param param = v.elementAt(i);
            sb.append("<");
            sb.append(param.getKey());
            sb.append(">");
            sb.append(param.getValue());
            sb.append("</");
            sb.append(param.getKey());
            sb.append(">");
        }
        sb.append("</card:");
        sb.append(method);
        sb.append(">");
        sb.append("</soapenv:Body>");
        sb.append("</soapenv:Envelope>");
        Log.i("requestcontent",sb.toString());
        return sb.toString();
    }
    public static String requestContent(String v, String method){
        String namespace = Constant.NAMESPACE;
        if (v == null || method == null || namespace == null){
            return "";
        }
        StringBuffer sb = new StringBuffer("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:card=\"");
        sb.append(namespace);
        sb.append("\">");
        sb.append("<soapenv:Header/>");
        sb.append("<soapenv:Body>");
        sb.append("<card:");
        sb.append(method);
        sb.append(">");
        sb.append(v);
        sb.append("</card:");
        sb.append(method);
        sb.append(">");
        sb.append("</soapenv:Body>");
        sb.append("</soapenv:Envelope>");
        Log.i("requestcontent",sb.toString());
        return sb.toString();
    }
}
